﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace homeworke3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Ontest(object sender, EventArgs e)
        {
            MessageBox.Show("确实");
        }


        private void textBox1_DragDrop(object sender, DragEventArgs e)
        {
            textBox1.Text = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
        }

        private void textBox1_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                e.Effect = DragDropEffects.Copy;
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }
        }

        private void textBox2_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                e.Effect = DragDropEffects.Copy;
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }
        }

        private void textBox2_DragDrop(object sender, DragEventArgs e)
        {
            textBox2.Text = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string filePath1 = textBox1.Text;
            string filePath2 = textBox2.Text;
            string mergedContent = string.Empty;

            if (!string.IsNullOrEmpty(filePath1) && File.Exists(filePath1) &&
                !string.IsNullOrEmpty(filePath2) && File.Exists(filePath2))
            {
                mergedContent += File.ReadAllText(filePath1) + Environment.NewLine;
                mergedContent += File.ReadAllText(filePath2);

                string dataDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data");
                if (!Directory.Exists(dataDirectory))
                {
                    Directory.CreateDirectory(dataDirectory);
                }

                string mergedFilePath = Path.Combine(dataDirectory, "CombineFile.txt");
                File.WriteAllText(mergedFilePath, mergedContent);

                MessageBox.Show("Files merged successfully!");
            }
            else
            {
                MessageBox.Show("Please select both files correctly.");
            }
        }
    }

}
